<?php

namespace App\Console\Commands;

use App\Console\Commands\Common\CommonCommand;
use App\Imports\LngLogImport;
use App\Models\Car\CarInfo;
use App\Models\Car\Order;
use App\Models\Car\RentUnit;
use App\Models\Rbac\Permission;
use App\Models\User\User;
use Illuminate\Console\Command;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Schema;
use Maatwebsite\Excel\Facades\Excel;
use Kkokk\Poster\PosterManager;

class Demo extends CommonCommand {


    private $instance;

    public function handle() {


        $cars = CarInfo::query()->get();
        foreach ($cars as $car) {

            $temp =  explode('-', $car->insurance_date);
            $car->insurance_date = "2025-$temp[1]-$temp[2]";
            $car->save();
        }

        /*CarInfo::query()->create([
            'car_no'=>'鲁Q'.rand(1,100).strtoupper(randomChar(3)),
            'brand'=>'北汽',
            'seat_num'=>rand(4,8),
            'has_window'=>rand(1,1000)%2==0?'有':'无',
            'is_auto'=>rand(1,1000)%2==0?'是':'否',
            'color'=>rand(1,1000)%2==0?'白色':'黑色',
            'type'=>rand(1,1000)%2==0?1:2,
            'fix_date'=>date('Y-m-d')
        ]);*/



        /*$records = Order::query()->get(['rent_unit_id','car_count']);
        $res = [];
        $temp = [];

        foreach ($records as $record) {
            if(isset($res[$record->rent_unit_id])){
                $temp[$record->rent_unit_id]+=$record->car_count;
            }else{
                $temp[$record->rent_unit_id] = $record->car_count;
            }
        }

        //排序
        uasort($temp,function ($a,$b){
           return $a<$b;
        });

        //取前10个元素
        $countTop = 0;
        foreach ($temp as $k=>$v){
            $res[$k] = $v;
            $countTop++;
            if ($countTop>=10)break;
        }

        $top = [];

        foreach ($res as $rent_unit_id=>$rent_car_count){
            $top[] = [
                'rent_unit_id'=>$rent_unit_id,
                'rent_unit_name'=>RentUnit::query()->find($rent_unit_id)->unit_name??'未知',
                'rent_car_count'=>$rent_car_count
            ];
        }
        dd($top);*/
        return 0;
    }
}
